<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%String path = request.getContextPath(); %>
 
<html>
  <head>
    <title>My JSP 'userList.jsp' starting page</title>
     <link href="./css/Pager.css" rel="stylesheet" type="text/css" />
    <script src="./js/jquery.pager.js" type="text/javascript"></script>
  </head>
<html:form action="/login.do">
    
 <table cellpadding="0" cellspacing="0" border="1" align="center" width="800" onkeydown="keyDown(event);" >
	<tr>
		<td>
			<bean:message key="label.user.username"/>:<html:text property="user.sname"> </html:text>
		</td>
	<tr>
		<td>
			<input type="button" id="import" value="<bean:message key="label.common.import"/>">
			<input type="button" id="export" value="<bean:message key="label.common.export"/>">
			<input type="button" name="add" onclick="toAdd();" value="<bean:message key="label.common.add"/>">
			<input type="button" id="clear"  value="<bean:message key="label.common.clear"/>">
			<input type="button" id="search"  value="<bean:message key="label.common.search"/>">
		</td>
  	</tr>
   <tr>
   		<td>
   			 <div id="result"></div>   
   			 <div id="pager"></div> 
   		</td>
   </tr>
</table>
     
  <script>
  
  	var pageIndex=1;
  	var pageCount=0;
  	var allRow=0;
        
  	$(function() {
  		GetPageCount();//取得分页总数  
     	$("#pager").pager({ pagenumber: pageIndex, pagecount: pageCount, buttonClickCallback: PageClick });
     	PageClick(pageIndex);
	});
	
 PageClick = function(pageclickednumber) {
     $("#pager").pager({ pagenumber: pageclickednumber, pagecount: pageCount, buttonClickCallback: PageClick }); 
  	var sname=document.getElementById("user.sname").value;
  	 lock();
   $.post("login.do?method=getContext&pageBean.currentPage="+pageclickednumber+"&user.sname="+sname,function(data,status){  
   	unlock();
     var str="<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\" width=\"800\" height=\"250px\">";
     str+="<tr> <td valign=\"top\">"
     str+="<table cellpadding=\"0\" cellspacing=\"0\" border=\"1\" align=\"center\" width=\"100%\">";
      str+="<tr bgcolor=\"#6699CC\">";
      str+="<td>"+"<bean:message key="label.common.index"/>"+"</td>";
      str+="<td>"+"<bean:message key="label.user.username"/>"+"</td>";
      str+="<td>"+"<bean:message key="label.user.userpwd"/>"+"</td>";
      str+="<td>"+"<bean:message key="label.common.operate"/>"+"</td>";
      str+="</tr>";
     $.each(data,function(index,content){
      str+="<tr id=\"line_"+content.sid+"\">";
	      	str+="<td>"+(index+1)+"</td>";
	      	str+="<td>"+content.sname+"</td>";
	  		str+="<td>"+content.spassword+"</td>";
     	 	str+="<td>"
	      		str+="<a href=\"<%=path %>/login.do?method=toUpdate&sid="+content.sid+"\"><bean:message key="label.common.update"/></a>&nbsp;&nbsp;";
				str+="<a href=\"javascript:dle('"+content.sid+"');\"><bean:message key="label.common.delete"/></a>";
			str+="</td>";
      str+="</tr>";
     });
     str+="</table>";
     str+="<td><tr></table>";
     
     $("#result").html(str);
    },"json");
          
        }
  
  
	function dle(str)
	{
			 lock();
			  $.ajax({    
              url:'login.do?method=delete',
              type: "post",  
              data:{sid:str},        
              error:function(){                    
              	alert("error occured!!!");                    
              },                    
              success:function(data){  
	              if(data=="0")
	              {
	              	$("#search").click();
	              	unlock();
	              }      
              }                                     
      });  
       
	}
	function toAdd()
	{
	 	var f=document.forms[0];
		f.action="login.do?method=toAdd";
		f.submit();
	}
	
 
//上一页按钮click事件  
$("#search").click(function(){  
 		pageIndex=1; 	
		GetPageCount();//取得分页总数  
     	$("#pager").pager({ pagenumber: pageIndex, pagecount: pageCount, buttonClickCallback: PageClick });
     	PageClick(pageIndex);  
});  	
$("#clear").click(function(){  
 
	 document.getElementById("user.sname").value=""; 
});  
	

function keyDown(event)
{
    if(event.keyCode==13)
    {
		$("#search").click();
		event.returnValue=false; 
	}
}
//AJAX方法取得分页总数  
function GetPageCount()  
{  
var sname=document.getElementById("user.sname").value;
$.ajax({  
type: "post",  
dataType: "text",  
url: "login.do?method=getPageCount&user.sname="+sname,
async: false,  
success: function(msg){  
var str=msg.split(":");
allRow=str[0];
pageCount=str[1];
}  
});  
}  


 
  $("#export").click(function(){  
 
		var f=document.userForm;
		f.action="login.do?method=export";
		f.submit();
});	
$("#import").click(function(){  
		var f=document.userForm;
		f.action="login.do?method=toImport";
		f.submit();
		
});	


  </script>
  
   
 
  

</html:form>
</html>
